package guitforl.data.readers

import io.Source
import guitforl.data.readers.ReaderUtil._
import java.io.{BufferedReader, InputStream}

/**
 * Created by IntelliJ IDEA.
 * User: artem
 * Date: Jul 3, 2010
 * Time: 6:11:47 PM
 * To change this template use File | Settings | File Templates.
 */
class FileReader(private val fileName: String) extends DataReader {
	def getAllAsString = {
		val fileLines = Source.fromFile(fileName).getLines()
		fileLines.foldLeft("") {(a, b) => a + "\n" + b}
	}

	def getColumnsDoubleList():Array[Array[Double]] = {
    val br = new BufferedReader(new java.io.FileReader(fileName))
    def readLine(line: => String): List[Array[Double]] = line match {
      case null => List(new Array[Double](0))
      case s: String => s.split(" ").map(number => java.lang.Double.parseDouble(number)) :: readLine(line)
    }
    val result = readLine(br.readLine)    
    result.take(result.size - 1).transpose.map(_.toArray).toArray
  }

	def getRowsStringArray():List[Array[String]] = {
		val fileLines = Source.fromFile(fileName).getLines()
    val result = (for {line <- fileLines} yield line.split('|')).toList
    result
	}
}